package cn.anc.aonicardv.module.ui;

import android.Manifest;
import android.os.Bundle;
import android.os.Handler;

import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.XXPermissions;

import java.util.List;

import androidx.annotation.Nullable;
import cn.anc.aonicardv.R;
import cn.anc.aonicardv.module.ui.base.BaseActivity;
import cn.anc.aonicardv.util.ActivityUtils;
import cn.anc.aonicardv.util.AppPermissionsUtils;

/**
 * Created by yangdai on 2017/7/4.
 */

public class SplashActivity extends BaseActivity {


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_splash);
        super.onCreate(savedInstanceState);
        if (AppPermissionsUtils.checkAllLocation(SplashActivity.this)){
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    jumpActivity();
                }
            }, 2000);
        }else{
            mAllPremission = new String[]{
                    Manifest.permission.ACCESS_COARSE_LOCATION,
                    Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
                    Manifest.permission.READ_EXTERNAL_STORAGE
            };
            onRequestAll();
        }
    }

    private  String[] mAllPremission;

    public void onRequestAll() {
        XXPermissions.with(this)
                .permission(mAllPremission)
                .request(new OnPermissionCallback() {
                    @Override
                    public void onGranted(List<String> permissions, boolean all) {
                        if (AppPermissionsUtils.checkAllLocation(SplashActivity.this)) {
                            jumpActivity();
                        }
                    }
                    @Override
                    public void onDenied(List<String> permissions, boolean never) {
                        finish();
                    }
                });
    }

    private void jumpActivity() {
        ActivityUtils.jumpActivity(SplashActivity.this, MainActivity.class);
        finish();
    }

    @Override
    public void initVariable() {

    }

    @Override
    public void setListener() {

    }

    @Override
    public void initData() {

    }


}
